package com.cyneck.demo.exception;

import com.cyneck.demo.model.ApiResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>Description: ExceptionAspectHandler</p>
 *
 * @author Eric Lee
 * @version v1.0.0
 * @since 2020/9/15 15:34
 **/
@ControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    @ResponseBody
    ApiResponseEntity handleException(Exception e) {
        LOGGER.error(e.getMessage(), e);
        ApiResponseEntity response = ApiResponseEntity.fail(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
        return response;
    }

}